package dfs_bfs.test17;


import java.util.ArrayList;
import java.util.List;

/**
 * 电话号码的字母组合
 *
 * @author code_yc
 * @version 1.0
 * @date 2020/7/9 8:16
 */
public class Solution1 {

    // 方法一 ： 使用循环的方式
    public List<String> letterCombinations(String digits) {
        ArrayList<String> res = new ArrayList<>();
        if (digits == null || digits.length() == 0) return res;
        String[] dic = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        res.add("");
        for (int i = 0; i < digits.length(); i++) {
            char[] temp = dic[digits.charAt(i) - '2'].toCharArray();
            List<String> now = new ArrayList<>();
            for (char c : temp) {
                for (String s : res) {
                    now.add(s + c);
                }
            }
            res = new ArrayList<>(now);
        }
        return res;
    }

}
